﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.Unity;
using System.Web.Mvc;

namespace SE.UI.Framework.DI
{

        public class UnityDependencyResolver : IDependencyResolver
        {
            private readonly IUnityContainer unity;

            public UnityDependencyResolver(IUnityContainer unity)
            {
                this.unity = unity;
            }

            public object GetService(Type serviceType)
            {
                try
                {
                    return this.unity.Resolve(serviceType);
                }
                catch (ResolutionFailedException)
                {
                    // By definition of IDependencyResolver contract, this should return null if it cannot be found.
                    return null;
                }
            }

            public IEnumerable<object> GetServices(Type serviceType)
            {
                try
                {
                    return this.unity.ResolveAll(serviceType);
                }
                catch (ResolutionFailedException)
                {
                    // By definition of IDependencyResolver contract, this should return null if it cannot be found.
                    return null;
                }
            }
        }

}